package br.uefs.dexa.rfframework.gui.config.dialogs;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.DefaultListModel;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.LayoutStyle;

import br.uefs.dexa.rfframework.gui.utils.ScreenUtils;

public class NewCollectionDialog extends ConfigDialog {
	
	private static final int NAME_FIELD_WIDTH = 350;
	
	private static final int NAME_FIELD_HEIGHT = 30;
	
	private static final int DIR_FIELD_WIDTH = 293;
	
	private static final int DIR_FIELD_HEIGHT = 30;
	
	private NewCollectionController controller = new NewCollectionController();

	private JPanel mainPanel;
	
	private JPanel fieldsPanel;
	
	private JPanel collectionNamePanel;
	
	private JPanel collectionDirPanel;
	
	private JPanel featuresPanel;
	
	private JTextField nameTextField;
	
	private JTextField dirTextField;
	
	private JButton browseButton;
	
	private JButton indexButton;
	
	private JList featureList;
	
	private List<FeatureListItem> features;
	
	
	public NewCollectionDialog()
	{
		super();
		setTitle("New Collection");
		setDescriptio("Create a new image collection");
		mainPanel = getMainPanel();
		mainPanel.setLayout(new GridBagLayout());
		compose();
	}
	
	public void showDialog()
	{
		pack();
		setVisible(true);
	}
	
	private void compose()
	{
		buildFieldsPanel();
		buildFeaturesPanel();
		
		mainPanel.add(fieldsPanel);
		//mainPanel.add(featuresPanel);
	}
	
	private void buildFieldsPanel()
	{
		fieldsPanel = new JPanel();
		fieldsPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
		
		JLabel nameLabel = new JLabel("Collection name:");
		JLabel locationLabel = new JLabel("Collection location:");
		
		nameTextField = new JTextField();
		dirTextField = new JTextField();
		
		browseButton = new JButton("Browse");
		
		GroupLayout layout = new GroupLayout(fieldsPanel);
		fieldsPanel.setLayout(layout);
		
		layout.setAutoCreateGaps(true);
		layout.setAutoCreateContainerGaps(true);
		
		
		layout.setHorizontalGroup(
				layout.createSequentialGroup()
					.addGroup(layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
							.addComponent(nameLabel)
							.addComponent(locationLabel))
					//.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
					.addGroup(layout.createParallelGroup()
							 .addComponent(nameTextField, GroupLayout.PREFERRED_SIZE, 200, GroupLayout.PREFERRED_SIZE)
							 .addComponent(dirTextField, GroupLayout.PREFERRED_SIZE, 200, GroupLayout.PREFERRED_SIZE))
					//.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
					.addComponent(browseButton)
					
		);
		
		layout.setVerticalGroup(
				layout.createSequentialGroup()
					.addGroup(layout.createParallelGroup()
							.addComponent(nameLabel)
							.addComponent(nameTextField, GroupLayout.PREFERRED_SIZE, 26, GroupLayout.PREFERRED_SIZE))
					.addGroup(layout.createParallelGroup()
							.addComponent(locationLabel)
							.addComponent(dirTextField, GroupLayout.PREFERRED_SIZE, 26, GroupLayout.PREFERRED_SIZE)
							.addComponent(browseButton))
		);
		
		
	
	}
	
	private void buildFeaturesPanel()
	{
		featuresPanel = new JPanel();
		featuresPanel.setBorder(BorderFactory.createTitledBorder("Features"));
		featuresPanel.add(new JLabel("Features Panel"));
	}

	@Override
	public void okButtonAction() 
	{
		this.dispose();
	}

	@Override
	public void cancelButtonAction() 
	{
		this.dispose();
	}
	
	
	
	public static void main(String[] args) {
		
		EventQueue.invokeLater(new Runnable() {
			
			@Override
			public void run() {
				NewCollectionDialog dialog = new NewCollectionDialog();
				dialog.showDialog();
				
			}
		});
		
		
	}
	
	
}
